package state;

import lombok.AllArgsConstructor;

/**
 * 可以抽奖的状态
 */
@AllArgsConstructor
public class CanRaffleState implements State {
    private final RaffleActivity activity;

    /**
     *  扣除积分，然后把状态设置为不能抽奖
     */
    @Override
    public void deductPoints(int currentPoints) {
        if (currentPoints >= 50) {
            System.out.println("扣除50积分，您可以继续抽奖");
            activity.setPoints(currentPoints - 50);
            // 切换状态
            activity.setState(activity.getCanRaffleState());
        } else {
            System.out.println("积分不足，不能抽奖");
            activity.setState(activity.getNoRaffleState());
        }
    }

    /**
     * 是否抽中奖品
     */
    @Override
    public boolean raffle() {
        System.out.println("正在抽奖，请稍等！");
        int random = (int) (Math.random() * 10);
        if (random == 0) {
            activity.setState(activity.getDispenseState());
            return true;
        } else {
            System.out.println("很遗憾，您没有中奖！");
            activity.setState(activity.getNoRaffleState());
            return false;
        }
    }

    /**
     * 发放奖品
     */
    @Override
    public void dispensePrize() {
        System.out.println("没有奖品发放！");
    }
}
